package com.buleqr.service.impl;

import com.buleqr.dao.UserDao;
import com.buleqr.dto.request.SearchFriendsGroupsQuery;
import com.buleqr.dto.response.SearchFriendsGroupsVo;
import com.buleqr.dto.response.ToApplyFriendVo;
import com.buleqr.mapper.UserMapper;
import com.buleqr.pojo.User;
import com.buleqr.security.JwtUser;
import com.buleqr.service.FriendsGroupSearchService;
import com.buleqr.utils.security.SecurityUtils;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *搜索好友与群
 */
@Service
public class FriendsGroupSearchServiceImpl implements FriendsGroupSearchService {

    private final UserDao userDao;

    public FriendsGroupSearchServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public SearchFriendsGroupsVo searchFriendsGroups(SearchFriendsGroupsQuery query) {
        JwtUser loginUser = SecurityUtils.getLoginUser();
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        List<ToApplyFriendVo> toApplyFriendVos = ((UserMapper) userDao.getBaseMapper()).searchFriend(query,loginUser.getId());
        SearchFriendsGroupsVo friendsGroupsVo = new SearchFriendsGroupsVo();
        friendsGroupsVo.setToApplyFriendVos(toApplyFriendVos);
        return friendsGroupsVo;
    }
}
